package com.tchintech.pay.view.activity;

import android.os.Handler;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ListView;

import com.tchintech.pay.R;
import com.tchintech.pay.adapter.MessageAdapter;
import com.tchintech.pay.adapter.MyPagerAdapter;
import com.tchintech.pay.delegate.MessageDelegate;
import com.tchintech.pay.frame.presenter.ActivityPresenter;
import com.tchintech.pay.model.entity.Mymessage;
import com.tchintech.pay.model.entity.ResultBean;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/7/11 0011.
 */

/**
 * 我的消息
 */
public class MessageActivity extends ActivityPresenter<MessageDelegate> implements View.OnClickListener {
    private ViewPager viewpager;
    private Handler handler;
    private List<Mymessage> list;
    private MessageAdapter[] messageAdapter;
    private ListView[] listview;
    private int cuttPager;
    @Override
    protected void initView() {
        super.initView();
        viewpager=viewDelegate.getVp();
        viewDelegate.setOnClickListener(this, R.id.real_public,R.id.real_private,R.id.iv_back);
        cuttPager=0;
        list=new ArrayList<Mymessage>();
        viewDelegate.selectTitle(cuttPager);
        viewpager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
            }
            @Override
            public void onPageSelected(int position) {
                //选中的ui改变
                cuttPager=position;
                viewDelegate.selectTitle(position);
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });
        handler();
        setView();
    }

    /**
     * 绑定listVIew与adapter
     */
    private void setView(){
        LayoutInflater inflater = LayoutInflater.from(this);
        View contenter0 = inflater.inflate(R.layout.viewpager_message, null);
        View contenter1 = inflater.inflate(R.layout.viewpager_message, null);
        List<View> viewList = new ArrayList<View>();
        viewList.add(contenter0);
        viewList.add(contenter1);
        PagerAdapter pagerAdapter = new MyPagerAdapter(viewList);
        viewpager.setAdapter(pagerAdapter);
        messageAdapter=new MessageAdapter[viewList.size()];
        listview=new ListView[viewList.size()];
        for(int i=0;i<viewList.size();i++){
            messageAdapter[i]=new MessageAdapter(this,list);
            listview[i]= (ListView)viewList.get(i).findViewById(R.id.list_message);
            listview[i].setAdapter(messageAdapter[i]);
        }

    }


    private  void handler(){
        handler=new Handler(){


        };
    }

    @Override
    protected void initData() {
        super.initData();
        viewDelegate.getback().setVisibility(View.VISIBLE);
        viewDelegate.getTitle().setText("我的消息");

    }

    @Override
    public void httpCallback(String resultBean, int what) {
        super.httpCallback(resultBean, what);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.real_public:
                //公共
                viewpager.setCurrentItem(0, true);
                break;
            case R.id.real_private:
                //个人
                viewpager.setCurrentItem(1, true);
                break;
            case R.id.iv_back:
                finish();
                break;
        }
    }

    @Override
    protected Class<MessageDelegate> getDelegateClass() {
        return MessageDelegate.class;
    }
}
